package cz.khfotbal.beans;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import cz.khfotbal.domain.Link;
import cz.khfotbal.service.LinkService;

@Component
@Scope(value = "session")
public class LinkBean {

	@Autowired
	private LinkService linkService;
	
	private Link newLink;
	private Link selectedLink;
	
	public LinkBean(){
		newLink = new Link();
	}
	
	public void createLink(){
		linkService.createLink(newLink);
		newLink = new Link();
	}
	
	public List<Link> getAllLinks(){
		return linkService.getAllLinks();
	}
	
	public void updateLink(){
		if (selectedLink != null){
			linkService.updateLink(selectedLink);
		}
	}
	
	public void deleteLink(){
		if (selectedLink != null){
			linkService.deleteLink(selectedLink);
		}
	}
	
	public Link getNewLink() {
		return newLink;
	}
	public void setNewLink(Link newLink) {
		this.newLink = newLink;
	}
	public Link getSelectedLink() {
		return selectedLink;
	}
	public void setSelectedLink(Link selectedLink) {
		this.selectedLink = selectedLink;
	}
	
	
}
